<!-- 用户编辑弹窗 -->
<template>
  <ele-modal width="680px"
             :visible="visible"
             :append-to-body="true"
             :close-on-click-modal="true"
             custom-class="ele-dialog-form"
             title="请修改技师的状态"
             @update:visible="updateVisible">
    <el-form ref="form"
             :model="form"
             label-width="82px">

      <el-radio-group v-model="form.technicianStatus">
        <el-radio :label="1">离线</el-radio>
        <el-radio :label="2">在线</el-radio>
        <el-radio :label="3">冻结中</el-radio>
        <el-radio :label="4">服务中</el-radio>
      </el-radio-group>

    </el-form>
    <template v-slot:footer>
      <el-button @click="updateVisible(false)">取消</el-button>
      <el-button type="primary"
                 :loading="loading"
                 @click="save">
        保存
      </el-button>
    </template>
  </ele-modal>
</template>
	
	<script>

export default {
  components: {},
  props: {

    // 弹窗是否打开
    visible: Boolean,
    // 修改回显的数据
    data: Object
  },
  data () {
    const defaultForm = {
      technicianStatus: 1
    };
    return {
      defaultForm,
      // 表单数据
      form: { ...defaultForm },
      // 表单验证规则
      rules: {

      },
      // 提交状态
      loading: false,
      // 是否是修改
      isUpdate: false
    };
  },
  computed: {
    // 是否开启响应式布局
    styleResponsive () {
      return this.$store.state.theme.styleResponsive;
    }
  },
  methods: {
    /* 保存编辑 */
    save () {
      this.$refs.form.validate((valid) => {
        if (!valid) {
          return false;
        }
        this.loading = true;
        const data = {
          ...this.form,
        };
        console.log("isUpdate", this.isUpdate)
        const saveOrUpdate = this.isUpdate ? updateUser : addUser;

        // saveOrUpdate(data)
        //   .then((msg) => {
        //     this.loading = false;
        //     this.$message.success('划拨成功！');
        //     this.updateVisible(false);
        //     this.$emit('done');
        //   })
        //   .catch((e) => {
        //     this.loading = false;
        //     this.$message.error(e.message);
        //   });
      });
    },
    /* 更新visible */
    updateVisible (value) {
      this.$emit('update:visible', value);
    }
  },
  watch: {
    visible (visible) {
      if (visible) {
        if (this.data) {
          this.$util.assignObject(this.form, {
            ...this.data,

          });
          this.isUpdate = true;
        } else {
          this.isUpdate = false;
        }
      } else {
        this.$refs.form.clearValidate();
        this.form = { ...this.defaultForm };
      }
    }
  }
};
	</script>
	<style lang="less" scoped>
/deep/.ele-dialog-form .el-dialog__body {
  padding-bottom: -1px;
  display: flex;
  justify-content: center;
}
</style>